package com.ruoyi.wechat.service.impl;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.constant.WechatConstants;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.wechat.domain.BskBanner;
import com.ruoyi.wechat.mapper.BskBannerMapper;
import com.ruoyi.wechat.service.IBskBannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class IBskBannerServiceImpl implements IBskBannerService {

    @Autowired
    private BskBannerMapper bannerMapper;

    @Override
    public List<BskBanner> selectBannerList(BskBanner banner) {
        return bannerMapper.selectBannerList(banner);
    }

    @Override
    public int updateBanner(BskBanner banner) {
        return bannerMapper.updateByPrimaryKeySelective(banner);
    }

    @Override
    public int insertBanner(BskBanner banner) {
        return bannerMapper.insert(banner);
    }

    @Override
    public BskBanner selectBannerById(Long bannerId) {
        return bannerMapper.selectByPrimaryKey(bannerId);
    }

    @Override
    public int deleteBannerByIds(String ids) {
        return bannerMapper.deleteBannerByIds(Convert.toLongArray(ids));
    }

    @Override
    public String checkBannerNameUnique(BskBanner banner) {
        Long bannerId = StringUtils.isNull(banner.getBannerId()) ? -1L : banner.getBannerId();
        BskBanner info = bannerMapper.checkBannerNameUnique(banner.getBannerName());
        if (StringUtils.isNotNull(info) && info.getBannerId().longValue() != bannerId.longValue())
        {
            return WechatConstants.BANNER_NAME_NOT_UNIQUE;
        }
        return WechatConstants.BANNER_NAME_UNIQUE;

    }
}
